package com.qf.exhandler;

import com.qf.vo.ResultVo;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExHandler {

    @ExceptionHandler(TokenException.class)
    public ResultVo handleTokenEx(TokenException tokenException){
        tokenException.printStackTrace();
        return new ResultVo(tokenException.getCode(), tokenException.getTokenMsg(), null);
    }


    @ExceptionHandler(Exception.class)
    public ResultVo handleEx(Exception exception){

        exception.printStackTrace(); // 将异常对象的所有信息打印到控制台

        ResultVo resultVo = new ResultVo();
        resultVo.setCode(-1);
        resultVo.setMsg(exception.getMessage());

        return resultVo;

    }

}
